package com.hpin.fansea.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hpin.fansea.R;
import com.hpin.fansea.bean.RadioResult;

import java.util.List;

/**
 * Created by Aaron on 15/9/17.
 */
public class RadioAdapter extends BaseAdapter {

    private Context context;
    private List<RadioResult.CellBroadcastList> radioLists;

    public RadioAdapter(Context context, List<RadioResult.CellBroadcastList> radioLists) {
        this.context = context;
        this.radioLists = radioLists;
    }

    public void setData(List<RadioResult.CellBroadcastList> radioLists) {
        this.radioLists = radioLists;
    }

    @Override
    public int getCount() {
        return radioLists.size();
    }

    @Override
    public Object getItem(int position) {
        return radioLists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {

            convertView = View.inflate(context, R.layout.item_community_broadcast, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_time.setText(radioLists.get(position).updateTime);
        viewHolder.tv_title.setText(radioLists.get(position).cbName);

        return convertView;
    }

    private class ViewHolder {
        public TextView tv_time;
        public TextView tv_title;
    }
}
